package net.hangar5.xmlrpc;

/* CallWriter.java

The contents of this file are subject to the Mozilla Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.

The Original Code is "Hangar5 XMLRPC Library".

The Initial Developer of the Original Code is James D. Rudnicki.  
Portions created by James D. Rudnicki are
Copyright (C) 2001.  All Rights Reserved.

Contributor(s): 
*/
import java.util.*;

/** 
 * Generates XML-RPC call data.
 */
public class CallWriter extends XmlWriter {

  /** Generate method call XML
   */
  static public StringBuffer write( String strMethod, Vector vParams ) {
	StringBuffer sbBuild = new StringBuffer(200);
	
	try {
	  sbBuild.append( "<?xml version=\"1.0\"?><methodCall><methodName>" );
	  sbBuild.append( strMethod );
	  sbBuild.append( "</methodName>" );
	  if( vParams != null ) {
		sbBuild.append( "<params>" );
		Enumeration e = vParams.elements();
		Object o;
		while( e.hasMoreElements() ) {
		  o = e.nextElement();
		  sbBuild.append( "<param>" );
		  writeObject( sbBuild, o );
		  sbBuild.append( "</param>" );
		}
		sbBuild.append( "</params>" );
	  }
	  sbBuild.append( "</methodCall>" );
	}
	catch( RpcException x ) {
	  sbBuild = null;
	}
	
	return sbBuild;
  }  
} // end of class
